<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>键盘按下事件</title>
    <script src="js/vuejs-2.5.16.js"></script>

</head>
<body>
    <div id="app">
        <input type="text" @keydown="fn1($event)"/>
    </div>
    <script type="text/javascript">
        new Vue({
            el:"#app",
            data:{

            },
            methods:{
                fn1(event){
                    var keyCode=event.keyCode;
                    if (keyCode!=8){
                        if (keyCode<48||keyCode>57){
                            event.preventDefault();
                        }
                    }
                }
            }
        });
    </script>

</body>
</html>